package com.cskaoyan.javase.oop1._8call;

/**
 *
 * @since 11:43
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class Demo {
    public static void main(String[] args) {
        Student s1 = new Student(18);
        Student s2 = new Student(81);
        // 方法可以改变对象的状态
        // swapStudentAge(s1, s2);
        // System.out.println(s1.age);
        // System.out.println(s2.age);

        swapStudentReference(s1, s2);
        System.out.println(s1.age);
        System.out.println(s2.age);
    }

    // 交换年龄
    public static void swapStudentAge(Student s1, Student s2) {
        int temp = s1.age;
        s1.age = s2.age;
        s2.age = temp;
    }

    public static void swapStudentReference(Student s1, Student s2) {
        Student temp = s1;
        s1 = s2;
        s2 = temp;
    }
}

class Student {
    int age;

    public Student(int age) {
        this.age = age;
    }
}